﻿Public Class modify_username

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            MsgBox("Supply all Fields")
        Else
            rs = New ADODB.Recordset
            rs.Open("SELECT * from Account", cn, 3, 2)
            If TextBox1.Text = rs.Fields("password").Value Then
                If TextBox2.Text.Length < 11 And TextBox2.Text.Length > 4 Then
                    rs = New ADODB.Recordset
                    rs.Open("SELECT * from account where password = '" & TextBox1.Text & "'", cn, 3, 2)
                    rs.Fields("Username").Value = TextBox2.Text
                    rs.Update()
                    rs.Close()
                    rs = Nothing
                    MsgBox("Successfully Updated")
                    MainScreen.Show()
                    Me.Close()
                Else
                    MsgBox("Username should be 5 to 10 characters only")
                End If
            Else
                MsgBox("The current password you have entered is wrong")
            End If
        End If


    End Sub

    Private Sub modify_username_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Module1.connect()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        accountmgnt.Show()
        Me.Close()
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub modify_username_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

    End Sub
End Class